<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
	<head>
		<title>登录页面</title>
		<script src="static/lib/js/jquery-2.1.4.min.js" type="text/javascript"></script>
	</head>
	<body>
		<form action="">
			<div>
				帐号：<input type="text" id="txt_account" name="account" />
			</div>
			<div>
				密码：<input type="password" id="txt_password" name="password" />
			</div>
			<div>
				<button id="login_button" type="button">登录</button>
			</div>
			<div class="tips_msg"></div>
		</form>
		<script type="text/javascript">
			$(function(){
				$("#login_button").click(function() {
		            var $account = $("#txt_account");
		            var $password = $("#txt_password");
		            var $code = $("#txt_code");
		            if ($account.val() == "") {
		            	$account.focus();
		                formMessage('请输入登录帐号。');
		                return false;
		            } else if ($password.val() == "") {
		                $password.focus();
		                formMessage('请输入登录密码。');
		                return false;
		            } else if ($code.val() == "") {
		                $code.focus();
		                formMessage('请输入验证码。');
		                return false;
		            } else {
		                $("#login_button").attr("disabled", true).text("loading...");
		                $.ajax({
		                    url: "login",
		                    data: { account: $.trim($account.val()), password: $.trim($password.val()) },
		                    type: "post",
		                    dataType: "json",
		                    success: function (data) {
		                        if (data.result) {
		                            $("#login_button").text("登录成功，正在跳转...");
		                            window.setTimeout(function () {
		                                window.location.href = "index.html";
		                            }, 100);
		                        } else {
		                            $("#login_button").removeAttr('disabled').text("登录");
		                            $("#imgcode").trigger("click");
		                            $code.val('');
		                            formMessage(data.message);
		                        }
		                    }
		                });
		            }
			})
		})
		function formMessage(msg) {
            $('.tips_msg').html(msg);
        }
		</script>
	</body>
</html>
